home *** CD-ROM | disk | FTP | other *** search
- Path: news.halcyon.com!usenet
- From: normanb@halcyon.com (Norm Bryar)
- Newsgroups: comp.lang.c++
- Subject: Re: Template help...
- Date: Thu, 25 Jan 1996 17:51:03 GMT
- Organization: Northwest Nexus Inc.
- Message-ID: <4e8ftc$lm6@news.halcyon.com>
- References: <31039FBD.167EB0E7@uci.edu>
- NNTP-Posting-Host: blv-pm11-ip18.halcyon.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- Would it be repugnant to use two types in your template, one for the
- block type, one for the search key type? You could, conceivably,
- define operator< and operator== for several search keys in struct
- a_block and create different a_temps to search them with the different
- keys.
-
- template <class element, class key>
- struct temp {
- ...
- }
- typedef temp<a,char*> a_temp
-
- --Norm
-
- Doug Semler <drsemler@uci.edu> wrote:
-
- >Question about templating:
-
- >I have a template
-
- >template
- >< class element >
- >struct temp {
- > ... // elements in template, ctors, etc. implementing linked list
- >};
-
- >and define my types such:
-
- >typedef struct a_block *a;
- >typedef <a> a_temp;
- >typedef a_temp a_list;
-
- >typedef struct b_block *b;
- >typedef <b> b_temp;
- >typedef b_temp b_list;
-
- >a_list A;
- >b_list B;
-
- >My problem is this...I want to find elements from list A based on a
- >character string, and list B based on an integer. The code is the
- >same (traverse list until found) and I would like to be able to say
- >A->find_element(char *id); or
- >B->find_element(int i);
-
- >(I have overloaded == function for char * types BTW)
- >Is it possible?
-
- >--
- >Doug Semler | drsemler@uci.edu
- >University of California, Irvine | Send all flames to /dev/null
- >Information and Computer Science | Of course these are *MY* opinions
- >http://www.ics.uci.edu/~dsemler | When in doubt, RTFM!
-
-
-